Sub D3DUtil_SetTextureSampling(bEnable As Boolean, w As Long, h As Long, levels As Long, fmt As CONST_D3DFORMAT, transfmt As CONST_D3DFORMAT, transcolor As Long)
Function D3DUtil_IntersectTriangleCull(ByRef v0 As D3DVECTOR, ByRef v1 As D3DVECTOR, ByRef v2 As D3DVECTOR, vDir As D3DVECTOR, vOrig As D3DVECTOR, t As Single, u As Single, v As Single) As Boolean
Dim edge1 As D3DVECTOR
Dim edge2 As D3DVECTOR
Dim pvec As D3DVECTOR
Dim tvec As D3DVECTOR
Dim qvec As D3DVECTOR
Dim det As Single
Dim fInvDet As Single
'find vectors for the two edges sharing vert0
D3DXVec3Subtract edge1, v1, v0
D3DXVec3Subtract edge2, v2, v0
'begin calculating the determinant - also used to caclulate u parameter
D3DXVec3Cross pvec, vDir, edge2
'if determinant is nearly zero, ray lies in plane of triangle
det = D3DXVec3Dot(edge1, pvec)
If (det < 0.0001) Then
Exit Function
End If
'calculate distance from vert0 to ray origin
D3DXVec3Subtract tvec, vOrig, v0
'calculate u parameter and test bounds
u = D3DXVec3Dot(tvec, pvec)
If (u < 0 Or u > det) Then
Exit Function
End If
'prepare to test v parameter
D3DXVec3Cross qvec, tvec, edge1
'calculate v parameter and test bounds
v = D3DXVec3Dot(vDir, qvec)
If (v < 0 Or (u + v > det)) Then
Exit Function
End If
'calculate t, scale parameters, ray intersects triangle